
package editor.map.elements
{
	import com.neroking.resource.Download;
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import flashx.textLayout.formats.TextAlign;

	/**
	 * @author 缺硒
	 */
	public class Teleport extends Npc
	{
		
		
		// 传送点描述
		private var _info:String;
		// 传送目的地id
		private var _toId:String;
		private var _skin:MovieClip;
		private var _label:TextField;
		private var _toIdLabel:TextField;
		private var _mainCircle:Shape;
		public var startCircle:Sprite;
		
		// 构造函数
		public function Teleport(color:uint = 0xff0000)
		{
			super();
			
			_mainCircle = new Shape();
			_mainCircle.graphics.beginFill(color,0.8);
			_mainCircle.graphics.drawCircle(50,50,30);
			_mainCircle.graphics.endFill();
			
			_label = new TextField();
			_label.x = -18;
			_label.y = 7;
			_label.background=true;
			_label.backgroundColor=0xffffff;
			_label.selectable = false;
			_label.autoSize = TextAlign.LEFT;
			
			_toIdLabel = new TextField();
			_toIdLabel.x = -18;
			_toIdLabel.y = 27;
			_toIdLabel.background = true;
			_toIdLabel.backgroundColor = 0xffffff;
			_toIdLabel.selectable = false;
			_toIdLabel.autoSize = TextAlign.LEFT;
			
			startCircle = new Sprite();
			startCircle.graphics.beginFill(0x000000);
			startCircle.graphics.drawCircle(0,0,20);
			startCircle.graphics.beginFill(0xff0000);
			startCircle.graphics.drawCircle(0,0,2);
			startCircle.graphics.endFill();
			startCircle.x = 100;
			startCircle.y = 100;
			startCircle.addEventListener(MouseEvent.MOUSE_DOWN, onStartDown);
			startCircle.addEventListener(MouseEvent.MOUSE_UP, onStartUp);
			
			_mainContainer.addChildAt(_mainCircle, 0);
			
			Download.load("https://repo.xd.com/svn/tg.doc/Client/assets/swf/gate.swf", onGateOk, [Download.SELF]);
			
			_mainContainer.addChild(_label);
			_mainContainer.addChild(_toIdLabel);
			addChild(startCircle);
		}
		
		private function onGateOk(load:Loader):void
		{
			var temClass:Class = load.contentLoaderInfo.applicationDomain.getDefinition("Gate") as Class;
			_skin = new temClass();
			_skin.mouseChildren = false;
			_skin.mouseEnabled = false;
			addChildAt(_skin,0);
		}
		
		
		private function onStartDown(e:MouseEvent):void
		{
			startCircle.startDrag();
		}
	
		private function onStartUp(e:MouseEvent):void
		{
			startCircle.stopDrag();
		}
		
		
		public function set label(value:String):void
		{
			_label.text = value;
		}

		public function get info():String
		{
			return _info;
		}

		public function set info(value:String):void
		{
			_info = value;
		}

		public function get toId():String
		{
			return _toId;
		}

		public function set toId(value:String):void
		{
			_toId = value;
			_toIdLabel.text = "to: " + _toId;
		}
		//
	}
}